package com.zq;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.function.Consumer;

/**
 * @ProjectName: ybxy6
 * @Titile: HashSteDemo
 * @Author: zqsfg
 * @Description: TODO
 */
public class HashSteDemo {
    public static void main(String[] args) {
        LinkedList<String> list = new LinkedList<>();
        list.addFirst("ysq");
        list.addLast("zq");
        list.addLast("zq");
        list.addLast("zxy");
        list.addLast("zq");
        System.out.println(list);
        //可以去重 new HashSet<String>(list)
        ArrayList<String> list1 = new ArrayList<>(new HashSet<String>(list));
        System.out.println(list1);


        //1.创建HashSet对象
        HashSet<String> hashSet = new HashSet<>();
        //2.添加元素（元素不重复、无序）
        hashSet.add("zq");
        hashSet.add("钟焮玥");
        hashSet.add("杨斯淇");
//        hashSet.add("杨斯淇");
//        hashSet.add("杨斯淇");
//        hashSet.add("杨斯淇");
//        hashSet.add("杨斯淇");
        hashSet.add("郑巧");
        System.out.println(hashSet);

        //3.迭代器：取数据
        System.out.println("-----------------3.---------------");
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }

        //for循环
//        for (int i = 0,i<hashSet.size();i++){
//
//        }用不了
        //4.增强for循环
        System.out.println("----------------4.----------------");
        for (String s : hashSet) {
            System.out.println("name="+s);
        }
        System.out.println("--------------------------------");
        int[] arr={1,2,3,4,5,6,7,8,9,10};
        for (int i : arr) {
            System.out.println(i);
        }
        //5.取数据：Lambda表达式
        System.out.println("----------------5.----------------");
//        hashSet.forEach(new Consumer<String>() {
//            @Override
//            public void accept(String s) {
//                System.out.println(s);
//            }
//        });
//        hashSet.forEach(s ->System.out.println(s));

        hashSet.forEach(System.out::println);
        //练习
        System.out.println("---------------练习-----------------");
        //1.迭代器
        Iterator<String> iterator1 = hashSet.iterator();
        while (iterator1.hasNext()) {
            String next = iterator1.next();
            System.out.println(next);
        }
        System.out.println("--------------------------------");
        //2.增强for循环
        for (String s:hashSet){
            System.out.println(s);
        }
        System.out.println("--------------------------------");
        //3.lambda表达式
        hashSet.forEach(System.out::println);



        System.out.println("--------------------------------");
        Student  student = new Student("zq",18);
        System.out.println(student.toString());



    }
}
